package org.hamster.common.services
{
	[Event(name="itemLoadAsyncComplete",     type="org.hamster.common.services.events.CacheEvent")]
	[Event(name="itemLoadAsyncComplete",     type="org.hamster.common.services.events.CacheEvent")]
	[Event(name="itemListLoadAsyncComplete", type="org.hamster.common.services.events.CacheEvent")]
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.Dictionary;
	
	public class SimpleCacheService extends EventDispatcher implements ICacheService
	{
		private var dict:Dictionary;
		
		public function SimpleCacheService()
		{
			super(this);
			
			dict = new Dictionary();
		}
		
		public function putItem(key:String, value:*):*
		{
			return dict[key] = value;
		}
		
		public function getItem(key:String):*
		{
			return dict[key];
		}
		
		public function putItemAsync(key:String, data:*):void
		{
			// do nothing
		}
		
		public function putAll(keyList:Array, valueList:Array):Array
		{
			var length:int = Math.min(keyList.length, valueList.length);
			for (var i:int = 0; i < length; i++) {
				dict[keyList[i].toString()] = valueList[i];
			}
			return valueList;
		}
		
		public function putAllAsync(keyList:Array, dataList:Array):void
		{
			// do nothing
		}
		
		public function clean(key:String):*
		{
			var item:* = this.getItem(key);
			dict[key] = null;
			return item;
		}
		
		public function cleanAll():void
		{
			this.dict = new Dictionary();
		}
		
		public function exists(key:String):Boolean
		{
			return dict.hasOwnProperty(key) && dict[key] != null;
		}
		
		public function size():int
		{
			return 0;
		}
	}
}